home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10995 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.ner.bbnplanet.net!forest!groy
  2. From: groy@forest.drew.edu (I can't think of a nickname)
  3. Newsgroups: comp.lang.c
  4. Subject: HELP!!!!  --very important!!--
  5. Message-ID: <1996Mar21.000242.138161@forest>
  6. Date: 21 Mar 96 00:02:42 EST
  7. Organization: Drew University
  8.  
  9. Please Help....
  10. I need to get this program working... the function set_diff is supposed to 
  11. find the differences between the two arrays (a[] and b[]) and put the 
  12. differences(if any) in array c[]....
  13.  
  14. int set_diff(int a[], int b[], int c[], int max) {
  15.   int *first = a;
  16.   int *second = b;
  17.   int *third = c;
  18.   int *endfirst = first + max;
  19.   int *endsecond = second + max;
  20.   int count=0;
  21.   /*first compare each value of a to b and note the differences*/
  22.  
  23.    for(first = a,second = b; first< endfirst, second<endsecond;
  24.                          first++,second++){
  25.            if (*first == *second)
  26.              count =1;
  27.  
  28.            if (count != 1){
  29.            *third = *first;
  30.            third++;     }   count =0;
  31.         } /* end of for(first ... */
  32. return count;
  33. } /*end of set_diff */
  34. int main () {
  35.    int a[MAX], b[MAX], c[MAX * 2]; /*the three arrays */
  36.    int count;
  37.    int decide;
  38.  
  39.    printf("Enter %i integers \n",MAX);
  40.  
  41.    for (count = 0; count < MAX; count++)
  42.        scanf("%i", &a[count]);
  43.    printf("Enter %i more integers \n",MAX);
  44.    for (count =0; count < MAX; count++)
  45.        scanf("%i", &b[count]);
  46.    decide =set_diff(a, b, c, MAX);
  47.    /* now print the three arrays */
  48.    printf("array a\n");
  49.    for(count = 0; count < MAX; count++)
  50.       printf("%2i ", a[count]);
  51.    printf("\narray b\n");
  52.    for(count = 0; count < MAX; count++)
  53.       printf("%2i ", b[count]);
  54.    if (decide != 1) {
  55.    printf("\ndifference\n");
  56.    for(count = 0; count < (MAX * 2); count++)
  57.       printf("%2i ", c[count]); }
  58.    printf("\n");
  59. } /*end of main*/
  60.  
  61.  
  62.  
  63.  
  64.  
  65. Thankyou for any help.. please hurry I am running out of time...
  66.  
  67.  
  68.  
  69. Ps.. there are probbly two more programs on the way...
  70. Greg Roy
  71. Groy@drew.edu
  72.  
  73.  
  74.